const Service = require('egg').Service;

class StudentService extends Service {
    async getStudentList() {
        try {
            let studentList = await this.app.model.Student.findAll({
                include: {
                    model: this.ctx.model.Clazz
                }
            });
            return studentList
        } catch (e) {
            return null;
        }
    }
    async createStudent(name, achievement, clazz_id) {
        try {
            await this.app.model.Student.create({
                name: name,
                achievement: achievement,
                clazz_id: clazz_id
            })
            return true
        } catch (e) {
            return false
        }
    }
    async destroyStudent(id) {
        try {
            await this.app.model.Student.destroy({
                where: {
                    id
                }
            })
            return true
        } catch (e) {
            return false
        }
    }
}
module.exports = StudentService;